import { Node, Vec3, tween } from "cc";
import { Singleton } from "./Singleton";

export class EffectManager extends Singleton{
    /**
     * 打开一个UI window 展示效果
     * @param main 
     * @param duration 
     * @returns 
     */
    public openUIWindow(main:Node,duration: number=0.3):Promise<void>{
        return new Promise(resolve=>{
            main.setScale(0, 0,0);
			// 弹窗主体
			let tw = tween(main)
				.to(duration, { scale: new Vec3(1, 1, 1) }, { easing: 'backOut' })
				.call(()=>{
                    tw.stop()
                    tw=null
                    resolve();
                })
				.start();
        })
    }
    /**
     * 关闭一个UI window展示的效果
     * @param main 
     * @param duration 
     * @returns 
     */
    public closeUIWindow(main:Node,duration: number=0.3):Promise<void>{
        return new Promise(reslove=>{
            // 弹窗主体
			let tw = tween(main)
            .to(duration, { scale: new Vec3(0, 0, 0) }, { easing: 'backIn' })
            .set({ active: false })
            .call(()=>{
                tw.stop();
                tw=null
                reslove();
            })
            .start();
        })
    }
}